const jwt = require('jsonwebtoken')

// token规则
let secretKey = 'xuhua.top'

// 生成token
const generateToken = (data) => {
  let token = jwt.sign(data, secretKey, { expiresIn: 60 * 60 })
  return token
}
// token解析
const parsingToken = (token) => {
  return new Promise((resolve, reject) => {
    const { err, result } = jwt.verify(token, secretKey)
    result ? resolve(result) : reject(err)
  })
}

module.exports = {
  generateToken,
  parsingToken,
}
